package com.tit.safetycontacts.utils;

import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import android.app.Activity;
import android.content.Intent;

/**
 * @author LDM
 * IntentUtil.java
 * 2011-12-11 锟斤拷锟斤拷11:59:40
 */

public class BaseIntentUtil {
	
	/**
	 * IntentUtil默锟较碉拷锟斤拷转锟斤拷锟斤拷
	 * 使锟斤拷前锟斤拷要预锟斤拷锟斤拷锟斤拷
	 */
	public static int DEFAULT_ENTER_ANIM;
	public static int DEFAULT_EXIT_ANIM;
	
	private static Intent intent;
	
	/**
	 * 锟皆讹拷锟藉动锟斤拷 使锟斤拷
	 * DEFAULT_ENTER_ANIM 锟斤拷 DEFAULT_EXIT_ANIM 锟斤拷为锟斤拷锟斤拷效锟斤拷
	 * @param activity
	 * @param classes
	 */
	public static void intentDIY(Activity activity, Class<?> classes){
		intentDIY(activity, classes, null, DEFAULT_ENTER_ANIM, DEFAULT_EXIT_ANIM);
	}
	
	/**
	 * 锟皆讹拷锟藉动锟斤拷 使锟斤拷
	 * DEFAULT_ENTER_ANIM 锟斤拷 DEFAULT_EXIT_ANIM 锟斤拷为锟斤拷锟斤拷效锟斤拷
	 * @param activity
	 * @param classes
	 * @param paramMap 锟斤拷锟斤拷锟斤拷锟�
	 */
	public static void intentDIY(Activity activity, Class<?> classes, Map<String, String> paramMap){
		intentDIY(activity, classes, paramMap, DEFAULT_ENTER_ANIM, DEFAULT_EXIT_ANIM);
	}
	
	/**
	 * 锟皆讹拷锟藉动锟斤拷
	 * @param activity
	 * @param classes
	 * @param enterAnim enter锟斤拷源ID
	 * @param exitAnim  exit锟斤拷源ID
	 */
	public static void intentDIY(Activity activity, Class<?> classes, int enterAnim, int exitAnim){
		intentDIY(activity, classes, null, enterAnim ,exitAnim);
	}
	
	/**
	 * 锟皆讹拷锟藉动锟斤拷
	 * @param activity
	 * @param classes
	 * @param paramMap  锟斤拷锟斤拷锟斤拷锟�
	 * @param enterAnim enter锟斤拷源ID
	 * @param exitAnim  exit锟斤拷源ID
	 */
	public static void intentDIY(Activity activity, Class<?> classes, Map<String, String> paramMap, int enterAnim, int exitAnim){
		intent = new Intent(activity, classes);
		organizeAndStart(activity, classes, paramMap);
		if(enterAnim != 0 && exitAnim != 0){
			activity.overridePendingTransition(enterAnim, exitAnim);
		}
	}
	
	/**
	 * 系统默锟斤拷
	 * @param activity
	 * @param classes
	 * @param paramMap
	 */
	public static void intentSysDefault(Activity activity, Class<?> classes, Map<String, String> paramMap){
		organizeAndStart(activity, classes, paramMap);
	}
	
	private static void organizeAndStart(Activity activity, Class<?> classes, Map<String, String> paramMap){
		intent = new Intent(activity, classes);
		if(null != paramMap){
			Set<String> set = paramMap.keySet();
			for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
				String key = iterator.next();
				intent.putExtra(key, paramMap.get(key));
			}
		}
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		activity.startActivity(intent);
	}

}
